<template>
  <el-dialog
    title="明细"
    width="80%"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item label="类型">
        <!--        <el-input v-model="dataForm.companyName" placeholder="收货单位" clearable></el-input>-->
        <el-select filterable style="width: 100%" v-model="dataForm.type"  placeholder="类型">
          <el-option label="全部" value=""></el-option>
          <el-option
            v-for="item in typeList"
            :key="item.value"
            :label="item.name"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          type="date"
          :editable="false"
          v-model="dataForm.startTime"
          value-format="yyyy-MM-dd"
          style="width:150px;"
          placeholder="开始日期">
        </el-date-picker>
        ~
        <el-date-picker
          type="date"
          :editable="false"
          v-model="dataForm.endTime"
          style="width:150px;"
          value-format="yyyy-MM-dd"
          placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>


    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        prop="type"
        header-align="center"
        align="center"
        label="类型">
        <template slot-scope="scope">
          {{ scope.row.type == 0 ? '预支' : '支出' }}
        </template>
      </el-table-column>

      <el-table-column
        prop="tradeAmount"
        header-align="center"
        align="center"
        label="本次金额">
      </el-table-column>
      <el-table-column
        prop="balance"
        header-align="center"
        align="center"
        label="预支结余">
      </el-table-column>
      <el-table-column
        prop="licensePlate"
        header-align="center"
        align="center"
        label="车牌号">
      </el-table-column>

      <el-table-column
        prop="shipmentDate"
        header-align="center"
        align="center"
        label="运输日期">
      </el-table-column>
      <el-table-column
        width="160px"
        prop="createTime"
        header-align="center"
        align="center"
        label="操作时间">
      </el-table-column>
      <el-table-column
        prop="creator"
        header-align="center"
        align="center"
        label="操作员">
      </el-table-column>
      <el-table-column
        prop="note"
        header-align="center"
        align="center"
        label="备注">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </el-dialog>
</template>

<script>
import Utils from '@/utils/utils'

export default {
  data () {
    return {

      dataForm: {
        driverId: '',
        type: '',
        endTime: '',
        startTime: ''
      },
      visible: false,
      dataList: [],
      typeList: [{name: '预支', value: 0}, {name: '支出', value: 1}],
      driverList: [],
      receiveCompanyList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      detailVisible: false,
      importVisible: false

    }
  },
  methods: {
    init (id) {
      this.dataForm.startTime = Utils.getCurrentMonth()+'-01';
      this.dataForm.endTime = Utils.getCurrentDate();
      this.dataForm.driverId = id || 0

      this.visible = true

      this.getDataList()
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/tms/prepaybill/list'),
        method: 'get',
        params: this.$http.adornParams({
          driverId: this.dataForm.driverId,
          type: this.dataForm.type,
          startTime: this.dataForm.startTime,
          endTime: this.dataForm.endTime
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list
          this.totalPage = data.page.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    }

  }
}
</script>
